﻿app.controller('SystemConfigController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;


    $scope.GetDepartmentPageList = function (model, page) {
        $scope.PageLoading = true;
        $scope.TeamList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetDepartmentPageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    $scope.DepartmentList = ret.Data.Data;

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.AddDepartment = function (model, page) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/AddDepartment',
            data: { 'model': model }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/DepartmentList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.AddUser = function (model, page) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/AddUserInfo',
            data: { 'model': model, "IsEmployee": model.IsEmployee }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/UserPageList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetUserInfo = function (Id) {
        $scope.UserEditModel = {};
        $http({
            method: 'POST',
            url: '../SystemConfig/GetUserInfo',
            data: { 'Id': Id }
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserEditModel = ret.Data;
                $scope.UserEditModel.CreateTime = $filter('JSONDate')($scope.UserEditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                $scope.BindDepartmentList('Dep_Select', $scope.UserEditModel.DepartmentId);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.DeleteUserInfo = function (id,userno, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认删除该用户？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $scope.LoadingMsg = "正在提交,请稍后...";
                $http({
                    method: 'POST',
                    url: '../SystemConfig/DeleteUserInfo',
                    data: { 'Id': id, 'UserNo': userno }
                }).success(function (ret) {
                    $scope.PageLoading = false;
                    if (ret.Code == 100) {
                        alertify.alert(ret.Msg);
                        setTimeout(function () {
                            $scope.GetUserPageList($scope.SearchModel, page);
                        }, 2000);
                    } else {
                        alertify.alert(ret.Msg);
                    }
                }).error(function (data, status, headers, config) {
                    common.error($scope);
                    $scope.DataLoading = false;
                    alertify.alert("请检查网络");
                })
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.EditDepartment = function (model, page) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/EditDepartment',
            data: { 'model': model }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/DepartmentList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }
    $scope.EditUser = function (model, page) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/ModifyUserInfo',
            data: { 'model': model }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/UserPageList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }
    $scope.DeleteDepartment = function (id, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认删除该部门？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $scope.LoadingMsg = "正在提交,请稍后...";
                $http({
                    method: 'POST',
                    url: '../SystemConfig/DeleteDepartment',
                    data: { 'Id': id }
                }).success(function (ret) {
                    $scope.PageLoading = false;
                    if (ret.Code == 100) {
                        alertify.alert(ret.Msg);
                        setTimeout(function () {
                            $scope.GetDepartmentPageList($scope.SearchModel,page);
                        }, 2000);
                    } else {
                        alertify.alert(ret.Msg);
                    }
                }).error(function (data, status, headers, config) {
                    common.error($scope);
                    $scope.DataLoading = false;
                    alertify.alert("请检查网络");
                })
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetUserListByDepartment = function (Id) {
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetUserListByDepartment',
            data: { 'DepartmentId': Id }
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.GetDepartmentInfo = function (Id) {
        $scope.DepartmentModel = {};
        $http({
            method: 'POST',
            url: '../SystemConfig/GetDepartmentInfo',
            data: { 'Id': Id }
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.DepartmentModel = ret.Data;
                $scope.DepartmentModel.CompanyId = $scope.DepartmentModel.CompanyId + "";
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }
    $scope.GetCompanyList = function () {
        $scope.CompanyList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetCompanyList'
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.CompanyList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }


    $scope.GetTeamPageList = function (model, page) {
        $scope.PageLoading = true;
        $scope.TeamList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetTeamPageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TeamList = ret.Data.Data;
                    $scope.PageLoading = false;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetRolePageList = function (model, page) {
        $scope.PageLoading = true;
        $scope.TeamList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetSystemRolePageList',
            data: { "Text": model.Text },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.RoleList = ret.Data.Data;
                    $scope.PageLoading = false;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.BindDepartmentList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/GetDepartmentList'
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $("#" + control);
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (n.Id == defaultvalue)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.AddTeam = function (model) {
        if (model.DepartmentId == null || model.DepartmentId == '0') {
            alertify.alert("请选择班组所在部门！");
            return false;
        }
        if (model.TeamName == null || model.TeamName == '') {
            alertify.alert("请填写班组名称！");
            return false;
        }
        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SystemConfig/AddTeam',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 1) {
                    alertify.alert(ret.Msg);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.GetSystemModuleList = function () {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.ModuleList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetPageNodeList'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.ModuleList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetRoleList = function () {
        $scope.LoadingMsg = "页面加载中";
        $scope.RoleList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetRoleList'
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.RoleList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.GetUserDetail = function (id) {
        if (id == null)
            return false;
        setTimeout(function () {
            $http({
                method: 'POST',
                url: '../SystemConfig/GetUserDetail',
                data: { 'UserId': id }
            }).success(function (ret) {
                if (ret.Code == 100) {
                    $scope.UserDetail = ret.Data;
                    $scope.UserDetail.CreateTime = $filter('JSONDate')($scope.UserDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    for (var i = 0; i < $scope.UserDetail.RoleIdList.length; i++) {
                        var id = $scope.UserDetail.RoleIdList[i];
                        var controllist = $("[name='RoleItem']");
                        for (var i = 0; i < controllist.length; i++) {
                            if (id == controllist[i].value) {
                                controllist[i].checked = true;
                            }
                        }
                    }
                } else {
                    alertify.alert(ret.Msg);
                }
            }).error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })
        }, 2000);

    }

    $scope.GetEmployeeDetail = function (id) {
        if (id == null)
            return false;
        setTimeout(function () {
            $http({
                method: 'POST',
                url: '../SystemConfig/GetEmployeeDetail',
                data: { 'Id': id }
            }).success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.EmployeeDetail = ret.Data;
                    $scope.BindDepartmentList('Dep_Select', $scope.EmployeeDetail.DepartmentId);
                    $scope.EmployeeDetail.CreateTime = $filter('JSONDate')($scope.EmployeeDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                } else {
                    alertify.alert(ret.Msg);
                }
            }).error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })

        }, 2000);

    }


    $scope.CheckAll = function (Id, Type) {
        var result = $("#" + Id).is(":checked");
        var controls = $("input[id^='" + Type + "']");
        if (result) {
            for (var i = 0; i < controls.length; i++) {
                controls.prop("checked", true);
            }
        }
        else {
            for (var i = 0; i < controls.length; i++) {
                controls.prop("checked", false);
            }
        }
    }

    $scope.GetRoleDetail = function (id) {
        if (id == null)
            return false;
        $http({
            method: 'POST',
            url: '../SystemConfig/GetSystemRole',
            data: { 'Id': id }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.EditModel = ret.Data;
                $scope.EditModel.CreateTime = $filter('JSONDate')($scope.EditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }
    $scope.GetRoleModule = function (id) {
        $scope.PageLoading = true;
        setTimeout(function () {
            $http({
                method: 'POST',
                url: '../SystemConfig/GetRoleModule',
                data: { 'Id': id }
            }).success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        if (data.IsInsert) {
                            $("#Add_" + data.NodeId).prop("checked", true);
                        }
                        if (data.IsView) {
                            $("#View_" + data.NodeId).prop("checked", true);
                        }
                        if (data.IsDelete) {
                            $("#Delete_" + data.NodeId).prop("checked", true);
                        }
                        if (data.IsModify) {
                            $("#Modify_" + data.NodeId).prop("checked", true);
                        }
                    }

                } else {
                    alertify.alert(ret.Msg);
                }
            }).error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
        }, 2000);

    }
    $scope.AddRole = function (model, page) {
        if (model.RoleName == null || model.RoleName == "") {
            alertify.alert("请填写角色名称");
            return false;
        }
        var rolelist = [];
        var defaultpage = '';
        for (var i = 0; i < $scope.ModuleList.length; i++) {
            var module = $scope.ModuleList[i];
            for (var j = 0; j < module.NodeList.length; j++) {
                var node = module.NodeList[j];
                var role = {};
                role.NodeId = node.Id;
                role.IsInsert = $("#Add_" + node.Id).is(":checked");
                role.IsView = $("#View_" + node.Id).is(":checked");
                role.IsModify = $("#Modify_" + node.Id).is(":checked");
                role.IsDelete = $("#Delete_" + node.Id).is(":checked");
                if ($("#Default_" + node.Id).is(":checked") && role.IsView) {
                    defaultpage = $("#Default_" + node.Id).val();
                }
                rolelist.push(role);
            }
        }
        if (defaultpage == '') {
            alertify.alert("请选择默认跳转页面，并确认是否有查看权限！");
            return false;
        }
        model.DefaultPage = defaultpage;
        $http({
            method: 'POST',
            url: '../SystemConfig/AddSystemRole',
            data: { 'model': model, 'rolelist': rolelist }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/SystemRoleList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.EditRole = function (model, page) {
        if (model.RoleName == null || model.RoleName == "") {
            alertify.alert("请填写角色名称");
            return false;
        }
        var rolelist = [];
        var defaultpage = '';
        for (var i = 0; i < $scope.ModuleList.length; i++) {
            var module = $scope.ModuleList[i];
            for (var j = 0; j < module.NodeList.length; j++) {
                var node = module.NodeList[j];
                var role = {};
                role.NodeId = node.Id;
                role.IsInsert = $("#Add_" + node.Id).is(":checked");
                role.IsView = $("#View_" + node.Id).is(":checked");
                role.IsModify = $("#Modify_" + node.Id).is(":checked");
                role.IsDelete = $("#Delete_" + node.Id).is(":checked");
                rolelist.push(role);
                if ($("#Default_" + node.Id).is(":checked") && role.IsView) {
                    defaultpage = $("#Default_" + node.Id).val();
                }
            }
        }
        if (defaultpage == '') {
            alertify.alert("请选择默认跳转页面，并确认是否有查看权限！");
            return false;
        }

        model.DefaultPage = defaultpage;
        $http({
            method: 'POST',
            url: '../SystemConfig/EditSystemRole',
            data: { 'model': model, 'rolelist': rolelist }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                setTimeout(function () {
                    location.href = '../SystemConfig/SystemRoleList?page=' + page;
                }, 2000);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }


    $scope.GetUserPageList = function (searchmodel, page) {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetUserPageList',
            data: { 'model': searchmodel },
            params: { 'page': page }
        }).success(function (ret) {
            $scope.PageLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetEmployeePageList = function (searchmodel, page) {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.EmployeeList = [];
        $http({
            method: 'POST',
            url: '../SystemConfig/GetEmployeePageList',
            data: { 'model': searchmodel },
            params: { 'page': page }
        }).success(function (ret) {
            common.success($scope, null, ret);
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.EmployeeList = ret.Data.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.AddUserRole = function (userno) {
        var controllist = $("[name='RoleItem']");
        var roleIdlist = [];
        for (var i = 0; i < controllist.length; i++) {
            if (controllist[i].checked) {
                roleId = controllist[i].value;
                roleIdlist.push(roleId);
            }
        }
        if (roleId == null) {
            alertify.alert("请绑定角色");
            return false;
        }
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/AddUserRole',
            data: { 'UserNo': userno, 'RoleId': roleIdlist },
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.TransToUser = function (id, searchmodel, page) {
        if (id == null)
            return false;
        $http({
            method: 'POST',
            url: '../SystemConfig/EmployeeTransToUser',
            data: { 'Id': id },
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                $scope.GetEmployeePageList(searchmodel, page);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.TransToLeader = function (no, department, searchmodel, page) {
        if (no == null || department == null)
            return false;
        $http({
            method: 'POST',
            url: '../SystemConfig/AddDepartmentLeader',
            data: { 'EmployeeNo': no, "DepartmentId": department },
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                $scope.GetEmployeePageList(searchmodel, page);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.RemoveDepartmentLeader = function (no, department, searchmodel, page) {
        if (no == null || department == null)
            return false;
        $http({
            method: 'POST',
            url: '../SystemConfig/RemoveDepartmentLeader',
            data: { 'EmployeeNo': no, "DepartmentId": department },
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                alertify.alert(ret.Msg);
                $scope.GetEmployeePageList(searchmodel, page);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.AddEmployee = function (model, page) {
        if (model.DepartmentId == null || model.DepartmentId == '0') {
            alertify.alert("请选择所在部门！");
            return false;
        }
        else if (model.EmployeeNo == null || model.EmployeeNo == '') {
            alertify.alert("请填写工号！");
            return false;
        }
        else if (model.EmployeeName == null || model.EmployeeName == '') {
            alertify.alert("请填写姓名！");
            return false;
        }
        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SystemConfig/AddEmployee',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = '../SystemConfig/EmployeeList?page=' + page;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.EditEmployee = function (model) {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SystemConfig/EditEmployee',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.ResetPassword = function (userid) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认重置该用户登录密码？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $scope.LoadingMsg = "正在提交,请稍后...";
                $http({
                    method: 'POST',
                    url: '../Account/ResetPassword',
                    data: { 'UserId': userid }
                })
                    .success(function (ret) {
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert(ret.Msg);
                        } else
                            alertify.alert(ret.Msg);
                    })
                    .error(function (data, status, headers, config) {
                        common.error($scope);
                        $scope.PageLoading = false;
                        alertify.alert("请检查网络");

                    })
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.refreshOption = function (control) {
        $("#" + control).selectpicker('refresh');
    }

});



app.filter('HideCardNo', function () { //可以注入依赖
    return function (text) {
        if (text != null && text != "")
            return text.replace(/^(.{3})(?:\d+)(.{4})$/, "$1******$2");
    }
});
app.filter('GetFlowStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '0')
            return "已删除";
        else if (text == '1')
            return "编辑中";
        else if (text == '2')
            return "部门审批";
        else if (text == '3')
            return "单位审批";
        else if (text == '4')
            return "总部审核";
        else if (text == '5')
            return "已转发分管";
    }
});
app.filter('GetHiddenStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '1')
            return "未整改";
        else if (text == '2')
            return "整改中";
        else if (text == '3')
            return "已完成整改";
    }
});

app.filter('GetFlowStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '1')
            return "编辑中";
        else if (text == '2')
            return "待部门审批";
        else if (text == '3')
            return "待单位审批";
        else if (text == '4')
            return "待总部审核";
        else if (text == '5')
            return "审核完成";
    }
});

app.filter('GetStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '0')
            return "禁用";
        else if (text == '1')
            return "启用";

    }
});

app.filter('GetBoolStr', function () { //可以注入依赖
    return function (text) {
        if (text)
            return "是";
        else
            return "否";

    }
});
app.filter('GetWeekDay', function () {
    return function (enddate) {
        var endDate = new Date(enddate);
        var beginDate = new Date(endDate.getFullYear(), 0, 1);
        //星期从0-6,0代表星期天，6代表星期六
        var endWeek = endDate.getDay();
        if (endWeek == 0) endWeek = 7;
        var beginWeek = beginDate.getDay();
        if (beginWeek == 0) beginWeek = 7;
        //计算两个日期的天数差
        var millisDiff = endDate.getTime() - beginDate.getTime();
        var dayDiff = Math.floor((millisDiff + (beginWeek - endWeek) * (24 * 60 * 60 * 1000)) / 86400000);
        return Math.ceil(dayDiff / 7) + 1;
    }

});